package com.example.xunai.config;

import com.example.xunai.service.ai.strategy.AiModelFactory;
import com.example.xunai.service.ai.strategy.impl.BaiduStrategy;
import com.example.xunai.service.ai.strategy.impl.DeepSeekStrategy;
import com.example.xunai.service.ai.strategy.impl.QwenStrategy; // 新增导入
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RequiredArgsConstructor
public class AiModelInitializer implements CommandLineRunner {

    private final AiModelFactory aiModelFactory;
    private final AiModelConfig aiModelConfig;
    private final DeepSeekStrategy deepSeekStrategy;
    private final BaiduStrategy baiduStrategy;
    private final QwenStrategy qwenStrategy; // 新增注入

    @Override
    public void run(String... args) throws Exception {
        // 注册DeepSeek策略
        aiModelFactory.registerStrategy("deepseek", deepSeekStrategy);
        log.info("已注册DeepSeek模型策略");

        // 注册百度文心一言策略
        aiModelFactory.registerStrategy("baidu", baiduStrategy);
        log.info("已注册百度文心一言模型策略");

        // 注册通义千问策略
        aiModelFactory.registerStrategy("qwen", qwenStrategy);
        log.info("已注册通义千问模型策略");

        // 输出配置信息
        log.info(aiModelConfig.getConfigSummary());

        // 检查默认模型配置
        if (!aiModelConfig.isModelConfigured(aiModelConfig.getDefaultModel())) {
            log.warn("默认模型 '{}' 配置不完整，请检查配置", aiModelConfig.getDefaultModel());
        }

        // 检查模型配置
        checkModelConfiguration("deepseek", "DeepSeek");
        checkModelConfiguration("baidu", "百度文心一言");
        checkModelConfiguration("qwen", "通义千问");
    }

    private void checkModelConfiguration(String modelType, String modelName) {
        if (aiModelConfig.isModelConfigured(modelType)) {
            log.info("{}模型配置正常", modelName);
        } else {
            log.warn("{}模型配置不完整", modelName);
        }
    }
}